package net.learn.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.service.impl.BaseServiceImpl;
import net.learn.system.convert.SysAboutConvert;
import net.learn.system.dao.SysAboutDao;
import net.learn.system.entity.SysAboutEntity;
import net.learn.system.query.SysAboutQuery;
import net.learn.system.service.SysAboutService;
import net.learn.system.utils.UUIDUtil;
import net.learn.system.vo.SysAboutVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 关于我们
 */
@Service
@AllArgsConstructor
public class SysAboutServiceImpl extends BaseServiceImpl<SysAboutDao, SysAboutEntity> implements SysAboutService {

    @Override
    public PageResult<SysAboutVO> page(SysAboutQuery query) {
        IPage<SysAboutEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));

        return new PageResult<>(SysAboutConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    @Override
    public List<SysAboutVO> getList(SysAboutQuery query) {
        List<SysAboutEntity> entityList = baseMapper.selectList(getWrapper(query));

        return SysAboutConvert.INSTANCE.convertList(entityList);
    }

    private Wrapper<SysAboutEntity> getWrapper(SysAboutQuery query){
        LambdaQueryWrapper<SysAboutEntity> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(StrUtil.isNotBlank(query.getOrgId()), SysAboutEntity::getOrgId, query.getOrgId());
//        wrapper.like(StrUtil.isNotBlank(query.get()), SysHospitalEntity::getGoodName, query.getGoodName());
        return wrapper;
    }

    @Override
    public void save(SysAboutVO vo) {
        SysAboutEntity entity = SysAboutConvert.INSTANCE.convert(vo);
        entity.setUid(UUIDUtil.uuid());
        baseMapper.insert(entity);
    }

    @Override
    public void update(SysAboutVO vo) {
        SysAboutEntity entity = SysAboutConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        // 删除岗位
        removeByIds(idList);
    }
}